package com.ruoyi.web.wh.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.Log;
import com.ruoyi.framework.enums.BusinessType;
import com.ruoyi.web.wh.domain.WhRecord;
import com.ruoyi.web.wh.service.IWhRecordService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.Result;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 出入库记录Controller
 *
 * @author ruoyi
 * @date 2025-02-27
 */
@RestController
@RequestMapping("/wh/record")
public class WhRecordController extends BaseController {
    @Autowired
    private IWhRecordService whRecordService;

    /**
     * 查询出入库记录列表
     */
    @SaCheckPermission("wh:record:list")
    @GetMapping("/list")
    public TableDataInfo list(WhRecord whRecord) {
        startPage();
        List<WhRecord> list = whRecordService.selectWhRecordList(whRecord);
        return getDataTable(list);
    }


    /**
     * 获取出入库记录详细信息
     */
    @SaCheckPermission("wh:record:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id) {
        return success(whRecordService.selectWhRecordById(id));
    }


    /**
     * 获取出入库记录详细信息
     */
    @SaCheckPermission("wh:record:query")
    @GetMapping(value = "/putInByDay/{day}")
    public Result PutIn(@PathVariable("day") String time) {
        return success(whRecordService.selectWhPutInRecordByDay(time));
    }

    /**
     * 获取出入库记录详细信息
     */
    @SaCheckPermission("wh:record:query")
    @GetMapping(value = "/takeOutByDay/{day}")
    public Result TakeOut(@PathVariable("day") String time) {
        return success(whRecordService.selectWhTakeOutRecordByDay(time));
    }


    /**
     * 新增出入库记录
     */
    @SaCheckPermission("wh:record:add")
    @Log(title = "出入库记录", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody WhRecord whRecord) {
        return toAjax(whRecordService.insertWhRecord(whRecord));
    }

    /**
     * 修改出入库记录
     */
    @SaCheckPermission("wh:record:edit")
    @Log(title = "出入库记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody WhRecord whRecord) {
        return toAjax(whRecordService.updateWhRecord(whRecord));
    }

    /**
     * 删除出入库记录
     */
    @SaCheckPermission("wh:record:remove")
    @Log(title = "出入库记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids) {
        return toAjax(whRecordService.deleteWhRecordByIds(ids));
    }
}
